namespace NFreeMarker.Core
{
    /**
     * An instruction that indicates that that opening
     * and trailing whitespace on this line should be trimmed.
     * @version $Id: TrimInstruction.java,v 1.2 2003/08/29 09:42:38 revusky Exp $
     */

    internal sealed class TrimInstruction : TemplateElement
    {
        internal readonly bool Left;
        internal readonly bool Right;

        internal TrimInstruction(bool left, bool right)
        {
            Left = left;
            Right = right;
        }

        internal override void Accept(Environment env)
        {
            // This instruction does nothing at render-time, only parse-time.
        }

        public override string GetCanonicalForm()
        {
            if (Left && Right)
            {
                return "<#t>";
            }
            if (Left)
            {
                return "<#lt>";
            }
            if (Right)
            {
                return "<#rt>";
            }
            return "<#nt>";
        }

        public override string GetDescription()
        {
            string type = "";
            if (!Right) type = "left ";
            if (!Left) type = "right ";
            if (!Left && !Right) type = "no-";
            return type + "trim instruction";
        }

        internal override bool IsIgnorable()
        {
            return true;
        }
    }
}